$(document).ready(function(){

	$('.ui-tabs').tabs();

	// event handler for window resize
	$(window).resize(function(e){
		updateUI();
	});
	
	$(window).load(function(){
		updateUI();
	});
	//updateUI();
});

// event handler for window resize
function updateUI(){

	//alert($(window).width());
	if($(window).width() <= 480){

		// mobile view instructions
		tabsToAccordions();

	} else {

		// desktop view instructions
		accordionsToTabs();
	}

}

// changes tabs to accordions (jquery ui)
function tabsToAccordions(){
/*	$('.tabs').each(function(){
		var a = $('<div class="accordion">');
		var b = new Array();
		$(this).find('>ul>li').each(function(){
			b.push('<h3>'+$(this).html()+'</h3>');
		});
		var c = new Array();
		$(this).find('>div').each(function(){
			c.push('<div>'+$(this).html()+'</div>');
		});
		for(var i = 0; i < b.length; i++){
			a.append(b[i]).append(c[i]);
		}
		$(this).before(a);
		$(this).remove();
	})
	$('.accordion').accordion()*/
$(".ui-tabs").each(function(){var e=$('<div class="accordion">');var t=new Array;$(this).find(">ul>li").each(function(){t.push("<h3>"+$(this).html()+"</h3>")});var n=new Array;$(this).find(">div").each(function(){n.push("<div>"+$(this).html()+"</div>")});for(var r=0;r<t.length;r++){e.append(t[r]).append(n[r])}$(this).before(e);$(this).remove()});$(".accordion").accordion()
}

// changes accordions to tabs (jquery ui)
function accordionsToTabs(){
/*	$('.accordion').each(function(){
		var a = $('<div class="tabs">');
		var count = 0;
		var b = $('<ul>');
		$(this).find('>h3').each(function(){
			count++;
			b.append('<li><a href="#tabs-'+count+'">'+$(this).text()+'</a></li>');
		});
		var count = 0;
		var c = $('');
		$(this).find('>div').each(function(){
			count++;
			c=c.add('<div id="tabs-'+count+'">'+$(this).html()+'</div>');
		});
		a.append(b).append(c);
		$(this).before(a);
		$(this).remove();
	});
	$('.tabs').tabs();*/
$(".accordion").each(function(){var e=$('<div class="ui-tabs">');var t=0;var n=$("<ul>");$(this).find(">h3").each(function(){t++;n.append('<li><a href="#tabs-'+t+'">'+$(this).text()+"</a></li>")});var t=0;var r=$("");$(this).find(">div").each(function(){t++;r=r.add('<div id="tabs-'+t+'">'+$(this).html()+"</div>")});e.append(n).append(r);$(this).before(e);$(this).remove()});$(".ui-tabs").tabs()
}